package com.mr.cai.main.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.mr.cai.main.R;


/**
 * Created by Administrator on 16-2-28.
 */
public class ClassifyContentAdapter extends RecyclerView.Adapter<ClassifyContentAdapter.MyViewHolder> {
    private Context mContext;
    private MyViewHolder holder;
    private View view;
    private String[] test={
      "test",
            "test", "test", "test", "test", "test"
    };
    public ClassifyContentAdapter(Context mContext) {
        this.mContext = mContext;
    }
    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }
    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view=LayoutInflater.from(mContext).inflate(R.layout.classify_content_layout,null);
        holder =new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        holder.nRview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mOnItemClickLitener!=null){
                    mOnItemClickLitener.onItemClick(view,holder.getPosition());
                }

            }
        });
    }

    @Override
    public int getItemCount() {
        return test.length;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        View nRview;
        ImageView showImage,topFlag,bottomFlag;
        TextView title,des,price;
        public MyViewHolder(View itemView) {
            super(itemView);
            nRview=itemView.findViewById(R.id.adapter_root_view);
            showImage=(ImageView)itemView.findViewById(R.id.showImage);
            topFlag=(ImageView)itemView.findViewById(R.id.topFlag);
            bottomFlag=(ImageView)itemView.findViewById(R.id.bottomFlag);
            title=(TextView)itemView.findViewById(R.id.title);
            des=(TextView)itemView.findViewById(R.id.des);
            price=(TextView)itemView.findViewById(R.id.price);
        }
    }
    public void clearData(){
        view=null;
        mContext=null;
        test=null;
    }
}
